set scheme s2color

use "$project_path/data/4_regdata/dynamics/regdata_dynamics", clear

// Creating outcomes
gen mstd_diff_m1_ex_corruption = -std_diff_m1_ex_corruption
gen mstd_diff_m1_pub_corruption = -std_diff_m1_pub_corruption
egen diff_m1_chix_corruption = rowmean(std_diff_m1_accountability mstd_diff_m1_ex_corruption mstd_diff_m1_pub_corruption std_diff_m1_control_corruption)

// Computing effects
foreach v in std_diff_m1_accountability mstd_diff_m1_ex_corruption mstd_diff_m1_pub_corruption std_diff_m1_control_corruption diff_m1_chix_corruption {
	
	local v_short = subinstr("`v'", "mstd_", "", .)
	local v_short = subinstr("`v_short'", "std_", "", .)
	local v_short = subinstr("`v_short'", "diff_m1_", "", .)

	matrix res_mat_`v_short' = J(7, 3, .)
	matrix coln res_mat_`v_short' = tau ci_low ci_high
	local laglabels = "Placebo 0 1 2 3 4 5"
	matrix rown res_mat_`v_short' = `laglabels'

	local row = 0
	foreach k in -2 0 1 2 3 4 5 {
		local row = `row'+1
		rdrobust `v' runvar if relative_year==`k', level(90)
		matrix res_mat_`v_short'[`row',1] = e(tau_cl)
		matrix res_mat_`v_short'[`row',2] = e(ci_l_rb)
		matrix res_mat_`v_short'[`row',3] = e(ci_r_rb)
	}

}

** Appendix Figure E.10(a)

coefplot (matrix(res_mat_accountability[.,1]), ci((res_mat_accountability[.,2] res_mat_accountability[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("Government accountability index", size(vlarge)) xlabel(,labsize(large)) ylabel(,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E10a.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.10(b)

coefplot (matrix(res_mat_ex_corruption[.,1]), ci((res_mat_ex_corruption[.,2] res_mat_ex_corruption[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("(Minus) Executive corruption index", size(vlarge)) xlabel(,labsize(large)) ylabel(,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E10b.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.10(c)

coefplot (matrix(res_mat_pub_corruption[.,1]), ci((res_mat_pub_corruption[.,2] res_mat_pub_corruption[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("(Minus) Public sector corruption index", size(vlarge)) xlabel(,labsize(large)) ylabel(,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E10c.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.10(d)

coefplot (matrix(res_mat_control_corruption[.,1]), ci((res_mat_control_corruption[.,2] res_mat_control_corruption[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("Control of corruption index", size(vlarge)) xlabel(,labsize(large)) ylabel(,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E10d.pdf", as(pdf) name("Graph") replace

** Appendix Figure E.10(e)

coefplot (matrix(res_mat_chix_corruption[.,1]), ci((res_mat_chix_corruption[.,2] res_mat_chix_corruption[.,3])) offset(0) color(midblue) ciopts(lwidth(*3) lcolor(midblue) )) , yline(0) xline(1.5, lwidth(thick) lcolor(black%30)) vertical title("Absence of corruption index", size(vlarge)) xlabel(,labsize(large)) ylabel(,labsize(large)) xtitle("Years after the election", size(large)) graphregion(color(white)) legend(off) ytitle("Standard deviations", size(large))
graph export "$project_path/output/appendix_figures/Appendix_Figure_E10e.pdf", as(pdf) name("Graph") replace

